package com.cdks.wuxiu.api.service.mysql;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdks.wuxiu.api.component.constant.Constant;
import com.cdks.wuxiu.api.mapper.WithdrawMoneyConfigMapper;
import com.cdks.wuxiu.entity.mysql.WithdrawMoneyConfig;
import java.util.List;

import org.springframework.stereotype.Service;


/**
 * 提现金额配置表 服务实现类
 */
@Service
public class WithdrawMoneyConfigServiceImpl extends ServiceImpl<WithdrawMoneyConfigMapper, WithdrawMoneyConfig> implements WithdrawMoneyConfigService {
    @Override
    public WithdrawMoneyConfig getByMoneyWithType(int money, int type) {
        QueryWrapper<WithdrawMoneyConfig> wrapper  = new QueryWrapper<>();
        wrapper.lambda().le(WithdrawMoneyConfig::getMoney, money)
                        .eq(WithdrawMoneyConfig::getType, type)
                        .eq(WithdrawMoneyConfig::getStatus, Constant.ENABLE_YES)
                        .orderByDesc(WithdrawMoneyConfig::getMoney);
        
        return baseMapper.selectOne(wrapper.last("LIMIT 1"));
    }

    @Override
    public List<WithdrawMoneyConfig> getValidListByType(int type) {
        QueryWrapper<WithdrawMoneyConfig> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(WithdrawMoneyConfig::getStatus, Constant.ENABLE_YES)
                        .eq(WithdrawMoneyConfig::getType, type)
                        .select(WithdrawMoneyConfig::getMoney,
                                WithdrawMoneyConfig::getFee);
        
        return baseMapper.selectList(wrapper);
    }
}
